﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.IO;
using System.Drawing.Imaging;
using System.Data.SqlClient;
using System.Configuration;
using System.Data.Sql;
using System.Data.SqlTypes;
using System.Web.SessionState;
using System.ComponentModel;
using System.Data;
using System.Web.UI.HtmlControls;
using System.Net.Mail;
using System.Text;
using System.Net;
using System.Web.Security;
using System.Runtime.InteropServices;




namespace iResume
{
    public partial class jobSeekerViewJobPost : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ArrayList jobSeekerViewJob = new ArrayList();
            string jobID = (string)(Session["jobID"]);
            if (jobID == null)
            {
                Response.Redirect("loginpage.aspx");
            }
            jobSeekerViewJob = DBManager.retrieveJobPostJobSeeker(jobID);
            Recruiter r = new Recruiter();
            r = (Recruiter)jobSeekerViewJob[0];
            Image1.ImageUrl = "recruiterDisplayImage.ashx?id=" + r.Email;
            //Company Information
            lblCompanyName.Text = r.CompanyName;
            lblCompanyURL.Text = r.CompanyURL;
            lblCompanyAddress.Text = r.CompanyAddress;
            lblPostalCode.Text = r.PostalCode;
            lblCompanyProfile.Text = r.CompanyProfile;
            lblSalaryRange.Text = r.SalaryRange;
            lblJobPosition.Text = r.JobPosition;
            lblCategory.Text = r.Category;
            lblDescription.Text = r.JobDescription;
            //Personal Information
            lblName.Text = r.PersonInCharge;
            lblEmail.Text = r.Email;
            lblContactNumber.Text = r.ContactNum;

           
            
        }

        protected void btnSend_Click(object sender, EventArgs e)
        {
            ArrayList sendResumes = new ArrayList();
            string email = (string)(Session["username"]);
            sendResumes = DBManager.retrievejs(email);
            JobSeeker j = new JobSeeker();
            j = (JobSeeker)sendResumes[0];

            Session["email"] = lblEmail.Text;
            string username = (string)(Session["email"]);
            
            


            //create the message
            MailMessage mail = new MailMessage();
            //add the email address we will be sending the message to
            mail.To.Add(username);
            //add our email here
            mail.From = new MailAddress("iResumee@gmail.com");
            //email's subject
            mail.Subject = email + " " + "Resume" ;
            //email's body, this is going to be html. note that we attach the image as using cid

            //The respective jobseeker has requested to post their resume to your job post 
            //and please follow up on the respective jobseeker.

            mail.Body = "Hi" + " " + lblName.Text + ",<br>" +
                "<br>The respective jobseeker has requested to post their resume to your job post and please follow up on the respective jobseeker. <br>" +
                 "<br>" + "<b>" + "Job Seeker Information" + "<b>" + "</br>" +
                 "<br>" + "Name: " + j.FullName + "</br>" +
                 "<br>" + "Email: " + email + "</br>" +
                 "<br>" + "Contact No. : " + j.ContactNo + "</br>" +
                 "<br>" + "Job Category: " + j.Jobcategory + "</br>" +
                 "<br>" + "Profile: " + j.Profile + "</br>" +
                 "<br>" + "Education: " + j.Education + "</br>" +
                 "<br>" + "Skill: " + j.Skills + "</br>";

            //set email's body to html
            mail.IsBodyHtml = true;

            //add our attachment
            //Attachment imgAtt = new Attachment(Server.MapPath("re.gif"));
            //give it a content id that corresponds to the src we added in the body img tag
            //imgAtt.ContentId = "re.gif";
            //add the attachment to the email
            //mail.Attachments.Add(imgAtt);

            //setup our smtp client, these are Gmail specific settings
            SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
            client.EnableSsl = true; //ssl must be enabled for Gmail
            //our Gmail account credentials
            NetworkCredential credentials = new NetworkCredential("iResumee@gmail.com", "yiweileeling");
            //add credentials to our smtp client
            client.Credentials = credentials;

            try
            {
                //try to send the mail message
                client.Send(mail);
                demo.Visible = true;
                btnSend.Enabled = false;
            }
            catch
            {
                //some feedback if it does not work
                //Messagelbl.Text = "Fail";
            }
       }

        protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect( "searchRecruiter.aspx");
        }

        protected void ImageButton2_Click1(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("searchRecruiter.aspx");
        }

        }
    }
